package com.zhongwang.mms.module.buy.controller;
import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.buy.model.PlanDetailsModel;
import com.zhongwang.mms.module.buy.model.PlanDetailsOpenModel;
import com.zhongwang.mms.module.buy.service.PlanDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zhongwang.mms.config.timingtask.StatisticalTimingTask.getVWProjectByCode;

/**
 * @Description: 项目计划明细 控制层
 * @Author: China.kxx
 * @Date: 2020/04/04 21:52
 */
@Slf4j
@Controller
@RequestMapping("/buy/planTraManage")
public class PlanDetailsController extends BaseController {
    @Autowired
    private PlanDetailsService planDetailsService;
    /**
     * 项目列表
     * @param rppProjectCode
     * @return list
     */
    @GetMapping("proDetail/{code}")
    public String detailCode(@PathVariable("code") String rppProjectCode,Model model){

        model.addAttribute("types",planDetailsService.findTypes(1000, rppProjectCode));
        model.addAttribute("rppProjectCode",rppProjectCode);
        model.addAttribute("project",getVWProjectByCode(rppProjectCode));
        model.addAttribute("projectStatus",planDetailsService.projectExecutionStatus(rppProjectCode));
        model.addAttribute("plan",planDetailsService.plansToTag(rppProjectCode));
        model.addAttribute("material",planDetailsService.materialNum(rppProjectCode));
        return "buy/planTraManage/detail";
    }


    /**
     * 项目明细列表
     *
     * @param planDetailsModel 查询条件
     * @return detail
     */
    @ResponseBody
    @PostMapping("/detail")
    public JsonResult detail(PlanDetailsModel planDetailsModel) {
        startPage();
        List<PlanDetailsModel> list = planDetailsService.planDetail(planDetailsModel);
        return jsonResult(list);
    }
    /**
     *  计划变更明细
     * @param planDetailsOpenModel
     * @return alteration
     */
    @ResponseBody
    @PostMapping("/alteration")
    public JsonResult alteration(PlanDetailsOpenModel planDetailsOpenModel){
        List<PlanDetailsOpenModel> list = planDetailsService.alterationOpen(planDetailsOpenModel);
        return jsonResult(list);
    }
    /**
     *  指定明细
     * @param planDetailsOpenModel
     * @return appoint
     */
    @ResponseBody
    @PostMapping("/appoint")
    public JsonResult appoint(PlanDetailsOpenModel planDetailsOpenModel){
        List<PlanDetailsOpenModel> list = planDetailsService.appointOpen(planDetailsOpenModel);
        return jsonResult(list);
    }
    /**
     *  外购件明细
     * @param planDetailsOpenModel
     * @return appoint
     */
    @ResponseBody
    @PostMapping("/appointP")
    public JsonResult appointP(PlanDetailsOpenModel planDetailsOpenModel){
        List<PlanDetailsOpenModel> list = planDetailsService.appointPOpen(planDetailsOpenModel);
        return jsonResult(list);
    }
    /**
     *  出入库明细
     * @param planDetailsOpenModel
     * @return warehouse
     */
    @ResponseBody
    @PostMapping("/warehouse")
    public JsonResult warehouse(PlanDetailsOpenModel planDetailsOpenModel){
        List<PlanDetailsOpenModel> list = planDetailsService.warehouseOpen(planDetailsOpenModel);
        return jsonResult(list);
    }
    /**
     *  合报记录
     * @param planDetailsOpenModel
     * @return merPurchasingOpen
     */
    @ResponseBody
    @PostMapping("/merPurchasingOpen")
    public JsonResult merPurchasingOpen(PlanDetailsOpenModel planDetailsOpenModel){
        List<PlanDetailsOpenModel> list = planDetailsService.merPurchasingOpen(planDetailsOpenModel);
        return jsonResult(list);
    }

}
